<template>
    <view class="pob">
        <view class="bg"></view>
        <view class="df pr">
			<view @click="redirectPage(item.pagePath,index)" :class=" index === 2 ? 'nav-box pr w20' : 'nav-box' " v-for="(item,index) in tabbarList" :key="index">
				<image v-if="index !== 2" mode="aspectFill"  referrerPolicy='no-referrer' :src="act == index ? item.selectedIconPath : item.iconPath"></image>
				<image v-else mode="aspectFill" class="img36" :src="item.iconPath"></image>
				<view v-if="index !== 2" :class="act == index ? 'act-c' : ''"> 
					{{ item.title }} 
				</view>
				<view :class="'mt10 ' + (act == 2 ? 'act-c' : '')" v-else> {{ item.title }} </view>
				
				<text class="dot-nums f12 cf" v-if="index == 4 && ( unReadNum != 0 || grade == 0 )"></text>
			</view>
           <!-- <navigator class="nav-box" url="/pages/home/home" open-type="redirect" hover-class="none">
                <image mode="aspectFill"  referrerPolicy='no-referrer' :src="act == 1 ? 'https://wx.xtwaixie.com/img/ts1.png' : 'https://wx.xtwaixie.com/img/t1.png'"></image>
                <view :class="act == 1 ? 'act-c' : ''">首页</view>
            </navigator>
            <navigator class="nav-box" url="/pages/demand/demand" open-type="redirect" hover-class="none">
                <image mode="aspectFill"  referrerPolicy='no-referrer'   :src="act == 2 ? 'https://wx.xtwaixie.com/img/ts6.png' : 'https://wx.xtwaixie.com/img/t6.png'"></image>
                <view :class="act == 2 ? 'act-c' : ''">订单大厅</view>
            </navigator>
            <navigator class="nav-box pr w20" url="/pages/demand/subDemand" hover-class="none" open-type="navigate">
                <image mode="aspectFill" class="img36" src="https://wx.xtwaixie.com/img/adds.png"></image>
                <view :class="'mt10 ' + (act == 3 ? 'act-c' : '')">发布询价</view>
            </navigator>
            <navigator class="nav-box" url="/pages/shopping/shopping" open-type="redirect" hover-class="none">
                <image mode="aspectFill"  referrerPolicy='no-referrer'   :src="act == 4 ? 'https://wx.xtwaixie.com/img/ts2.png' : 'https://wx.xtwaixie.com/img/t2.png'"></image>
                <view :class="' ' + (act == 4 ? 'act-c' : '')">工厂地图</view>
            </navigator>
            <navigator class="nav-box" url="/pages/my/my" open-type="redirect" hover-class="none">
                <image mode="aspectFill"   referrerPolicy='no-referrer' :src="act == 5 ? 'https://wx.xtwaixie.com/img/ts5.png' : 'https://wx.xtwaixie.com/img/t5.png'"></image>
                <view :class="act == 5 ? 'act-c' : ''">我的{{unReadNum}}</view>
            </navigator> -->
        </view>
    </view>
</template>

<script>
const app = getApp();
import { mapState,mapActions } from 'vuex'
const http = require('../../utils/http');
export default {
    data() {
        return {
            act: 0,
			tabbarList:[
				{
					title:'首页',
					pagePath: "/pages/home/home",
					iconPath:'https://wx.xtwaixie.com/img/t1.png',
					selectedIconPath:'https://wx.xtwaixie.com/img/ts1.png'
				},
				{
					title:'接单大厅',
					pagePath: "/pages/demand/demand",
					iconPath:'https://wx.xtwaixie.com/img/t6.png',
					selectedIconPath:'https://wx.xtwaixie.com/img/ts6.png'
				},				{
					title:'发布询价',
					pagePath: "/pages/demand/subDemand",
					iconPath:'https://wx.xtwaixie.com/img/adds.png',
					selectedIconPath:'https://wx.xtwaixie.com/img/adds.png'
				},
				{
					title:'工厂地图',
					pagePath: "/pages/shopping/shopping",
					iconPath:'https://wx.xtwaixie.com/img/t2.png',
					selectedIconPath:'https://wx.xtwaixie.com/img/ts2.png'
				},
				{
					title:'我的',
					pagePath: "/pages/my/my",
					iconPath:'https://wx.xtwaixie.com/img/t5.png',
					selectedIconPath:'https://wx.xtwaixie.com/img/ts5.png'
				}
			],
			today:'',
			grade:-1
        };
    },
    /**
     * 组件的属性列表
     */
	computed: {
	    ...mapState('my', ['unReadNum'])
	},
	// onShow(){
	// 	console.log('tabbar')
	// },
    mounted() {
        // 处理小程序 ready 生命周期
		this.$nextTick(() => this.ready());
		
		this.today = new Date().toDateString();
		var pages = getCurrentPages();
		var currentPage = pages[pages.length - 1];
		var url = currentPage.route;
		const token = uni.getStorageSync('token')
		const login_code = uni.getStorageSync('is_login')
		if(token && login_code == 200){
			http.request('user/userInfo').then(res=>{
				this.grade = res.data.userInfo.grade
				const userInfo = res.data.userInfo
				const orderCount = res.data.orderCount
				const demandCount = res.data.demandCount
				let count = orderCount.count7 + demandCount.count3
				// console.log(count,1)
				http.request('user/settledInfo').then(rest=>{
					const info = rest.data.info.detail
					const lastVisit = uni.getStorageSync('lastVisitDate');
					const isMyPage = url === 'pages/my/my';
					const hasIncompleteInfo = !info.logo || !info.doorboard || info.main_products.length === 0
					// console.log(info.status ,'info.status != 2')
					const flag = !userInfo.settledStatus || info.status == 2
					if(hasIncompleteInfo || flag){
						this.updateUnReadNum(count + 1);
					} else {
						this.updateUnReadNum(count);
					}
				})
			})
		}
    },
    methods: {
		...mapActions('my', ['updateUnReadNum']),
        ready: function () {
            this.getUrl();
        },
		redirectPage(path,index){
			if(this.act == index) {
				return
			}
			if(index === 2){
				uni.navigateTo({
					url:path
				})
				return
			}
			if(index === 4){
				uni.redirectTo({
					url:path
				})
			}
			uni.redirectTo({
				url:path
			})
		},
        getUrl() {
            var pages = getCurrentPages();
            var currentPage = pages[pages.length - 1];
            var url = currentPage.route;
			
            if (url == 'pages/home/home') {
                this.act = 0
            } else if (url == 'pages/demand/demand') {
                this.act = 1
            } else if (url == 'pages/demand/subDemand') {
                this.act = 2
            } else if (url == 'pages/shopping/shopping') {
                this.act = 3
            } else if (url == 'pages/my/my') {
                this.act = 4
            }
        }
    },
    created: function () {}
};
</script>
<style scoped>
@import './tabbar.css';
</style>
